package com.aigou.admin.controller;

import com.aigou.admin.entity.Carousel_figure;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.entity.ResponseEntity;
import com.aigou.admin.service.Carousel_figureservice;
import com.aigou.admin.service.impl.Carousel_figureserviceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/carousel_figure")
public class Carousel_figureController extends BaseServlet{

    private Carousel_figureservice carousel_figureservice = new Carousel_figureserviceImpl();

    public void page(HttpServletRequest req, HttpServletResponse resp) throws IOException{
        String current = req.getParameter("current");
        String pageSize = req.getParameter("pageSize");
        PageEntity<Carousel_figure> carousel_figurePageEntity = carousel_figureservice.findCarousel_figurePage(Integer.valueOf(current),Integer.valueOf(pageSize));
        ResponseEntity.ok(resp,carousel_figurePageEntity);
    }

    public void findAll(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        List<Carousel_figure> carousel_figures = carousel_figureservice.findAll();
        ResponseEntity.ok(resp,carousel_figures);
    }

    public void find(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String id = req.getParameter("id");
        Carousel_figure carousel_figure = carousel_figureservice.findByid(id);
        ResponseEntity.ok(resp,carousel_figure);
    }

    public void save(HttpServletRequest req, HttpServletResponse resp) throws IOException{
        String id = req.getParameter("id");
        String url = req.getParameter("url");
        String sequence_num = req.getParameter("sequence_num");
        Carousel_figure carousel_figure =new Carousel_figure(id,url,Integer.valueOf(sequence_num));
        boolean rs = carousel_figureservice.save(carousel_figure);
        ResponseEntity.ok(resp,rs);
    }

    public void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException{
        String id = req.getParameter("id");
        boolean rs = carousel_figureservice.delete(id);
        ResponseEntity.ok(resp,rs);
    }

    public void update(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String id = req.getParameter("id");
        String url = req.getParameter("url");
        String sequence_num = req.getParameter("sequence_num");
        Carousel_figure carousel_figure =new Carousel_figure(id,url,Integer.valueOf(sequence_num));
        boolean rs = carousel_figureservice.update(carousel_figure);
        ResponseEntity.ok(resp,rs);
    }
}

